<?php include_once('header.php'); ?>
<?php include_once('MenuView.php'); ?>

<div id="profileContent">
   Bienvenido Profesor <?php // echo $userInfo->userName ?>,
    
    <div id="teacherExamFormDiv">
        <?php echo validation_errors(); ?>
        <?php echo form_open('Profesor/enableExam') ?>
        
            <div id="courseDiv">
                <select id="courseSelect" name="courseSelectInput">
                    <option value ="seleccione" selected>Seleccione Curso</option>
                    <?php foreach ($courses as $course){ ?>
                        <option value ="<?php echo $course->courseId; ?>" > <?php echo $course->name; ?></option>
                    <?php } ?>
                </select>
            </div>
        
            <div id="blockDiv">
                <select id="blockSelect" name="blockSelectInput">
                    <option value ="" selected>Seleccione Bloque</option>
                </select>
            </div>
        
            <div id="signInDiv">
                <input id="enableButton" value="Habilitar" type="submit" />
            </div> 
        </form>
    </div>
</div>


<script type="text/javascript">
     
    $(document).ready(function(){
        $('#blockSelect').attr('disabled', true);
    });
    
    $('#courseSelect').change(function() {
        $('#blockSelect').empty();
         $('#blockSelect').attr('disabled', false);
        loadCourses();
    });
    
    function loadCourses(){
        var baseurl = <?php echo site_url(); ?>;
        var courseId = $( "#courseSelect" ).val();
        var userId = <?php echo $userInfo->userId; ?>;
        
        $.ajax({
            url: baseurl+"Profesor/getBlocks",
            type: 'POST',
            async: false,
            dataType: 'text',
            data: {
                courseId_ajax : courseId,
                userId_ajax : userId
            },
            
            success: function(response) {
                //alert(response);
                var blocks = JSON.parse(response);
                $.each(blocks , function(k, block) {
                $('#blockSelect')
                    .append($("<option></option>")
                    .attr("value", block.blockId)
                    .text(block.name));
                }); 
            },
            
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
                
            }
        });
    }
    
</script>

<?php include_once('footer.php'); ?>